package com.controller;

import cn.hutool.db.PageResult;
import com.entity.TTreeNodeReq;
import com.entity.TTreeNode;
import com.server.ITTreeNodeService;
import com.util.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description: 多数据源测试
 * @author chenhailong
 * @ClassName: ITTreeNodeController
 * @date 2021/12/20 19:17
 * @Version 1.0
 */
@RestController
@RequestMapping("/node")
@Api(tags = "节点demo",value = "节点请求类")
public class ITTreeNodeController {


    @Autowired
    private ITTreeNodeService service;


    /**
     * @Description 新增功能
     * @Author chl
     * @Date 19:19 2021/12/20
     * @param tTreeNodeReq tTreeNodeReq
     * @return response response
     **/
    @PostMapping("/save")
    @ApiOperation(value = "新增节点")
    public Response add(@RequestBody TTreeNodeReq tTreeNodeReq) {
        TTreeNodeReq node = new TTreeNodeReq();

        boolean noneBlank = StringUtils.isNoneBlank("11", "2");
        service.add(node);
        return Response.createSuccess("成功");
    }

    @PostMapping("/select")
    @ApiOperation(value = "查询节点")
    public void select(@RequestBody TTreeNodeReq tTreeNodeReq) {
//        Test test = new Test();
//        BlockingQueue<String> queue = test.queue;
//
//        try {
//            queue.put(tTreeNodeReq.getName());
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        List<TTreeNode> list = service.list();
//        return Response.createSuccess("成功", list);
    }
    @PostMapping("/selectPage")
    @ApiOperation(value = "分页查询节点")
    public Response selectPage(@RequestBody TTreeNodeReq tTreeNodeReq) {
        PageResult<List<TTreeNode>> list = service.listPage(tTreeNodeReq);
        return Response.createSuccess("成功", list);
    }
}
